<?php

// ------------------------------------------------------------------------------------------------------------------------  
  function new_line($set_y=0)
  {
    global $global_margin;
    //global $global_position_y;
    //global $global_text_space;

    if($set_y>0) {
      $global_margin['position_y'] = $set_y;
    } else {
      $global_margin['position_y'] += $global_margin['text_space'];
    }
    return $global_margin['position_y'];
  }
   
// ------------------------------------------------------------------------------------------------------------------------  
  function set_text_space($size)
  {
    global $global_margin;
    return $global_margin['text_space'] = $size;
  }
   
// ------------------------------------------------------------------------------------------------------------------------  
  function current_line()
  {
    global $global_margin;
    return $global_margin['position_y'];
  }


// -- EXPERIMENTAL --------------------------------------------------------------------------------------------------------  
function center_mtext ($pdf, $x, $y, $text, $width = 210, $height= 10) {
	new_line($y);
	foreach (split ("\n", $text) as $line)
		$pdf->CenterText ($x, new_line(), $line, $width);
}

function draw_level ($pdf, $x, $y, $width, $height, $raise, $text, $end=false) {
	global $global_margin;
	if ($raise)
		$pdf->Line ($x, $y, $x+$width, $y);
	else
		$pdf->Line ($x, $y+$height, $x+$width,  $y+$height);
	if (!$end)
		$pdf->Line ($x+$width, $y, $x+$width, $y+$height);
	center_mtext ($pdf, $x, $y, $text, $width, $height);
}

function draw_level_chart () {
	$args = func_get_args();
	$pdf = array_shift ($args);
	$x = array_shift ($args);
	$y = array_shift ($args);
	$height = array_shift ($args);
	$raise  = array_shift ($args);
	while (count ($args) > 1) {
		$width = array_shift ($args);
		$text = array_shift ($args);
		draw_level ($pdf, $x, $y, $width, $height, $raise, $text, (count ($args) < 2));
		$x += $width;
		$raise = !$raise;
	}
}

function draw_little_arrow ($pdf, $x, $y, $scale = 1) {
    $pdf->Line($x - $scale, $y + (2*$scale), $x,	  $y);
    $pdf->Line($x,	    $y,		     $x + $scale, $y + (2*$scale));
    $pdf->Line($x - $scale, $y + (2*$scale), $x + $scale, $y + (2*$scale));
}

function blist_new ($start_at = NULL) {
	global $blist_n;
	return	($start_at != NULL)?
		($blist_n = $start_at - 1):
		(++$blist_n);
}

function blist_item () {
	global $edge;
	$args = func_get_args();
	$pdf = array_shift ($args);
	$first_line = array_shift ($args);
	$pdf->Text($edge["BULLET"], new_line(), blist_new () . ".");
	$pdf->Text($edge["INSET_LIST"], current_line(), $first_line);
	foreach ($args as $line)
		$pdf->Text($edge["INSET_LIST"], new_line(), $line);
}

   
?>
